package simtools.wizard;

import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.Rectangle;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;


public class Cache extends JInternalFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JPanel jPanel4 = null;
	private JButton jButton11 = null;
	private JButton jButton2 = null;
	private JTextField placementTextField = null;
	private JButton jButton = null;
	private JPanel filePanel = null;
	private JPanel jPanel1 = null;
	private JLabel jLabel1 = null;
	private JTextField jTextField = null;
	private JPanel jPanel2 = null;
	private JRadioButton jRadioButton = null;
	private JRadioButton jRadioButton1 = null;
	private JPanel jPanel3 = null;
	private JRadioButton jRadioButton2 = null;
	private JRadioButton jRadioButton3 = null;
	public static Cache getInstance() {
		return CacheHolder.instance;
	}
	
	private static class CacheHolder {
        private static Cache instance = new Cache();
    }
	
	/**
	 * This is the default constructor
	 */
	public Cache() {
		super();
		initialize();
	}

	/**
	 * This method initializes this
	 * 
	 * @return void
	 */
	private void initialize() {
		this.setSize(392, 344);
		this.setClosable(true);
		this.setContentPane(getJContentPane());
		this.setTitle("Cache Strategy");
		
		this.setResizable(false);
		Wizard.centralize(this);
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.add(getJPanel4(), null);
			jContentPane.add(getFilePanel(), null);
			jContentPane.add(getJPanel1(), null);
			jContentPane.add(getJPanel3(), null);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel4	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel4() {
		if (jPanel4 == null) {
			GridLayout gridLayout1 = new GridLayout();
			gridLayout1.setRows(1);
			gridLayout1.setHgap(10);
			jPanel4 = new JPanel();
			jPanel4.setName("jPanel4");
			jPanel4.setBounds(new Rectangle(113, 271, 156, 26));
			jPanel4.setLayout(gridLayout1);
			jPanel4.add(getJButton11(), null);
			jPanel4.add(getJButton2(), null);
		}
		return jPanel4;
	}

	/**
	 * This method initializes jButton11	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton11() {
		if (jButton11 == null) {
			jButton11 = new JButton();
			jButton11.setBounds(new Rectangle(90, 96, 67, 23));
			jButton11.setText("< Back");
			jButton11.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Wizard.jDesktopPane.removeAll();
					Wizard.jDesktopPane.repaint();
					
					Wizard.internal = Dataset.getInstance();
					Wizard.jDesktopPane.add(Wizard.internal);
					Wizard.internal.setVisible(true);
				}
			});
		}
		return jButton11;
	}

	/**
	 * This method initializes jButton2	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton2() {
		if (jButton2 == null) {
			jButton2 = new JButton();
			jButton2.setText("Next >");
			jButton2.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					Wizard.jDesktopPane.removeAll();
					Wizard.jDesktopPane.repaint();
					
					Wizard.internal = Summary.getInstance();
					Wizard.jDesktopPane.add(Wizard.internal);
					Wizard.internal.setVisible(true);
				}
			});
		}
		return jButton2;
	}

	/**
	 * This method initializes placementTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getPlacementTextField() {
		if (placementTextField == null) {
			placementTextField = new JTextField();
			placementTextField.setBounds(new Rectangle(15, 27, 245, 20));
		}
		return placementTextField;
	}

	/**
	 * This method initializes jButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getJButton() {
		if (jButton == null) {
			jButton = new JButton();
			jButton.setText("Open");
			jButton.setBounds(new Rectangle(265, 25, 64, 26));
			jButton.addActionListener(new java.awt.event.ActionListener() {
				public void actionPerformed(java.awt.event.ActionEvent e) {
					JFileChooser jFileChooser = new JFileChooser();  
					int status = jFileChooser.showOpenDialog(null);  
					if (status == JFileChooser.APPROVE_OPTION) { 
					  String selectedPath = jFileChooser.getSelectedFile().getAbsolutePath();
					  placementTextField.setText(selectedPath);
					}
				}
			});
		}
		return jButton;
	}

	/**
	 * This method initializes filePanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getFilePanel() {
		if (filePanel == null) {
			filePanel = new JPanel();
			filePanel.setLayout(null);
			filePanel.setBorder(BorderFactory.createTitledBorder(null, "Configuration File", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", Font.PLAIN, 11), new Color(0, 70, 213)));
			filePanel.setName("filePanel");
			filePanel.setBounds(new Rectangle(15, 68, 346, 70));
			filePanel.add(getPlacementTextField(), null);
			filePanel.add(getJButton(), null);
		}
		return filePanel;
	}

	/**
	 * This method initializes jPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel1() {
		if (jPanel1 == null) {
			jLabel1 = new JLabel();
			jLabel1.setBounds(new Rectangle(15, 76, 115, 20));
			jLabel1.setText("Cache Length in MBytes");
			jPanel1 = new JPanel();
			jPanel1.setLayout(null);
			jPanel1.setBorder(BorderFactory.createTitledBorder(null, "Or", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", Font.PLAIN, 11), new Color(0, 70, 213)));
			jPanel1.setVisible(true);
			jPanel1.setName("jPanel1");
			jPanel1.setBounds(new Rectangle(15, 144, 346, 111));
			jPanel1.add(jLabel1, null);
			jPanel1.add(getJTextField(), null);
			jPanel1.add(getJPanel2(), null);
		}
		return jPanel1;
	}

	/**
	 * This method initializes jTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getJTextField() {
		if (jTextField == null) {
			jTextField = new JTextField();
			jTextField.setBounds(new Rectangle(135, 76, 40, 20));
		}
		return jTextField;
	}

	/**
	 * This method initializes jPanel2	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel2() {
		GridLayout gridLayout2 = new GridLayout();
		gridLayout2.setRows(1);
		ButtonGroup cacheGroup = new ButtonGroup();
		if (jPanel2 == null) {
			jPanel2 = new JPanel();
			jPanel2.setBorder(BorderFactory.createTitledBorder(null, " ", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", Font.PLAIN, 11), new Color(0, 70, 213)));
			jPanel2.setLayout(gridLayout2);
			jPanel2.setBounds(new Rectangle(15, 15, 316, 48));
			jPanel2.add(getJRadioButton(), null);
			jPanel2.add(getJRadioButton1(), null);
			
			cacheGroup.add(getJRadioButton());
			cacheGroup.add(getJRadioButton1());
		}
		return jPanel2;
	}

	/**
	 * This method initializes jRadioButton	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton() {
		if (jRadioButton == null) {
			jRadioButton = new JRadioButton();
			jRadioButton.setText("LRU");
			jRadioButton.setName("jRadioButton");
			jRadioButton.setSelected(true);
		}
		return jRadioButton;
	}

	/**
	 * This method initializes jRadioButton1	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton1() {
		if (jRadioButton1 == null) {
			jRadioButton1 = new JRadioButton();
			jRadioButton1.setText("LFU");
			jRadioButton1.setName("jRadioButton1");
		}
		return jRadioButton1;
	}

	/**
	 * This method initializes jPanel3	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel3() {
		ButtonGroup choiceButtonGroup = new ButtonGroup();
		if (jPanel3 == null) {
			GridLayout gridLayout = new GridLayout();
			gridLayout.setRows(1);
			jPanel3 = new JPanel();
			jPanel3.setBorder(BorderFactory.createTitledBorder(null, "Option", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Tahoma", Font.PLAIN, 11), new Color(0, 70, 213)));
			jPanel3.setName("jPanel3");
			jPanel3.setBounds(new Rectangle(15, 2, 346, 64));
			jPanel3.setLayout(gridLayout);
			jPanel3.add(getJRadioButton2(), null);
			jPanel3.add(getJRadioButton3(), null);
			
			choiceButtonGroup.add(getJRadioButton2());
			choiceButtonGroup.add(getJRadioButton3());
		}
		return jPanel3;
	}

	/**
	 * This method initializes jRadioButton2	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton2() {
		if (jRadioButton2 == null) {
			jRadioButton2 = new JRadioButton();
			jRadioButton2.setText("Configuration File");
			jRadioButton2.setSelected(true);
		}
		return jRadioButton2;
	}

	/**
	 * This method initializes jRadioButton3	
	 * 	
	 * @return javax.swing.JRadioButton	
	 */
	private JRadioButton getJRadioButton3() {
		if (jRadioButton3 == null) {
			jRadioButton3 = new JRadioButton();
			jRadioButton3.setText("Falta um nome aqui");
		}
		return jRadioButton3;
	}

}  //  @jve:decl-index=0:visual-constraint="10,10"
